/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.todoterreno.utils;

import java.sql.*;

/**
 *
 * @author davex
 */
public class EstadoConexion {
    
    public static Connection createConnect() throws ClassNotFoundException, SQLException{
        Class.forName("org.postgresql.Driver");
        return DriverManager.getConnection("jdbc:mysql://localhost:3306/terreno", "terreno", "terreno");
//        Class.forName("com.mysql.jdbc.Driver");
//        return DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/terreno", "terreno", "terreno");
    }
    
    public static void closeResult(ResultSet rs) throws SQLException{
        if(rs!=null){
            rs.close();
        }
    }
    
    public static void closePrepared(PreparedStatement pst) throws SQLException{
        if(pst!=null){
            pst.close();
        }
    }
    
    public static void closeConect(Connection conn) throws SQLException{
        if(conn!=null){
            conn.close();
        }
    }
    
    public static void conect(){
        Connection conn=null;
        PreparedStatement pst=null;
        ResultSet rs=null;
        try{
            Class.forName("org.postgresql.Driver");
            conn=DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/terreno", "terreno", "terreno");
            pst=conn.prepareStatement("select idcasater, nombrefoto, precio, descripcion, cuartos, banios, tamanio, tipo, fecha, idestado, idubi from terreno.casaterreno");
            rs=pst.executeQuery();;
            while(rs.next()){
                System.out.println(rs.getString("idcasater")+","+ rs.getString("nombrefoto")+","+ rs.getString("precio")+","+ rs.getString("descripcion")+","+ rs.getString("cuartos")+","+ rs.getString("banios")+","+ rs.getString("tamanio")+","+ rs.getString("tipo")+","+ rs.getString("fecha")+","+ rs.getString("idestado")+","+ rs.getString("idubi"));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            try{
                if(rs!=null){
                    rs.close();
                }
                
                if(pst!=null){
                    pst.close();
                }
                
                if(conn!=null){
                    conn.close();
                }
            }catch(Exception ex){
                ex.printStackTrace();
            }
        }
    }
    
    
    
    public static void main(String[] args){
        conect();
    }
    
    
}
